home *** CD-ROM | disk | FTP | other *** search
-
- /* FLU2.KB-- like FLU.KB, but uses ask_menu to prompt user
- (See end of file for 'HOW TO RUN' info)
-
- Elementary (rule-based) medical diagnosis.
- The purpose of this file is to get you used to
- the rule notation. More sophisticated diagnosis
- would ordinarily use MIKE's frame system.
-
- Example symptom descriptors might be as follows
-
- Alice has a dry throat, a muzzy feeling in the head, a runny nose, sneezing
- and a slight transient fever, i.e. nothing worse than the common cold. In
- MIKE list style syntax this would look like the following :
-
- [alice, exhibits_symptom, dry_throat]
- [alice, exhibits_symptom, muzzy_feeling_head]
- [alice, exhibits_symptom, runny_nose]
- [alice, exhibits_symptom sneezing]
- [alice, exhibits_symptom, slight_transient_fever]
-
- Bert has a blocked and runny nose, he is sneezing, and his eyes are red,
- itchey, and watering. Bert is thus a hay-fever sufferer. The MIKE for the
- following is listed below.
-
- [bert, exhibits_symptom, runny_nose]
- [bert, exhibits_symptom, blocked_nose]
- [bert, exhibits_symptom sneezing]
- [bert, exhibits_symptom, red_itchy_watery_eyes]
-
- Another sufferer of the common cold in Charlie. He has a dry throat, a
- muzzy feeling in the head, a runny nose and sneezing, and has a slight
- transient fever. A MIKE version follows.
-
- [charlie, exhibits_symptom, dry_throat]
- [charlie, exhibits_symptom, muzzy_feeling_head]
- [charlie, exhibits_symptom, runny_nose]
- [charlie, exhibits_symptom sneezing]
- [charlie, exhibits_symptom, slight_transient_fever]
-
- Poor Donna's got laryngitis. Her symptoms are a persistent dry cough, a
- hoarse voice, laryngeal discomfort, slight transient fever, and malaise.
- A MIKE version follows:-
-
- [donna, exhibits_symptom, persistent_dry_cough]
- [donna, exhibits_symptom, hoarse_voice]
- [donna, exhibits_symptom, laryngeal_discomfort]
- [donna, exhibits_symptom, slight_transient_fever]
- [donna, exhibits_symptom, malaise]
-
- Eva has influenza. She has a persistent dry cough, a sore throat, slight
- transient fever, shivering, malaise, a headache, and is suffering from diffuse
- aches and pains.
-
- [eva, exhibits_symptom, persistent_dry_cough]
- [eva, exhibits_symptom, sore_throat]
- [eva, exhibits_symptom, slight_transient_fever]
- [eva, exhibits_symptom shivering]
- [eva, exhibits_symptom, malaise]
- [eva, exhibits_symptom, headache]
- [eva, exhibits_symptom, aches_and_pains]
-
- Finally Frank has seasonal allergic rhinitis, better known as hay fever.
- He has a runny nose, a blocked nose, sneezing, and soar red eyes.
-
- [frank, exhibits_symptom, runny_nose]
- [frank, exhibits_symptom, blocked_nose]
- [frank, exhibits_symptom sneezing]
- [frank, exhibits_symptom, red_itchy_watery_eyes].
-
- To 'seed' working memory with the above facts, you would need to use
- 'add'. For example:
-
- ?- add [frank, exhibits_symptom, runny_nose].
- ?- add [frank, exhibits_symptom, blocked_nose].
-
- In order for you to be able to do this easily we have added a simple
- menu style operation which allows you to select which symptoms
- a patient is exhibiting. To do this run fc. in the normal way.
- You will then get prompted by a menu of possible symptoms. From
- this menu you must then choose a series of options by typing the
- corresponding number to the symptom in the menu. MIKE will then
- try to diagnose what the patient has wrong with them
- */
- /* =============== diagnosis rule base ================== */
-
- rule patient_initialisation_Rule forward
- if
- start /* special symbol always in wm at first */
- then
- remove start & /* get rid of special symbol */
- query ['What is the name of the patient'] receives_answer Patient &
- add [patient, Patient] & /* record the name of the patient */
- /* the special primative ask_menu will add to working memory those items
- that you select from the menu */
- announce ['What symptoms does ',Patient,' exhibit?'] &
- ask_menu(Patient,exhibits_symptom,
- [
- dry_throat,
- muzzy_feeling_head,
- hoarse_voice,
- laryngeal_discomfort,
- persistent_dry_cough,
- sore_throat,
- slight_transient_fever,
- shivering,
- malaise,
- headache,
- aches_and_pains,
- runny_nose,
- blocked_nose,
- sneezing,
- red_itchy_watery_eyes
- ]) &
- add diagnosing.
-
-
- rule 1 forward
- if [patient,Patient] &
- [Patient, exhibits_symptom, runny_nose] &
- [Patient, exhibits_symptom, blocked_nose] &
- [Patient, exhibits_symptom, sneezing] &
- [Patient, exhibits_symptom, red_itchy_watery_eyes]
- then
- add [Patient, exhibits_symptom, hay_fever] & /* optional addition to working memory */
- announce [Patient, ' has hay fever.'].
-
- rule 2 forward
- if
- [patient,Patient] &
- [Patient, exhibits_symptom, persistent_dry_cough] &
- [Patient, exhibits_symptom, hoarse_voice] &
- [Patient, exhibits_symptom, laryngeal_discomfort] &
- [Patient, exhibits_symptom, slight_transient_fever] &
- [Patient, exhibits_symptom, malaise]
- then
- add [Patient, exhibits_symptom, laryngitis] &
- announce [Patient, ' has laryngitis.'].
-
- rule 3 forward
- if [patient,Patient] &
- [Patient, exhibits_symptom, dry_throat] &
- [Patient, exhibits_symptom, muzzy_feeling_head] &
- [Patient, exhibits_symptom, runny_nose] &
- [Patient, exhibits_symptom, sneezing] &
- [Patient, exhibits_symptom, slight_transient_fever]
- then
- add [Patient, exhibits_symptom, a, common_cold] &
- announce [Patient, ' has a common cold.'].
-
- rule 4 forward
- if
- [patient,Patient] &
- [Patient, exhibits_symptom, persistent_dry_cough] &
- [Patient, exhibits_symptom, sore_throat] &
- [Patient, exhibits_symptom, slight_transient_fever] &
- [Patient, exhibits_symptom, shivering] &
- [Patient, exhibits_symptom, malaise] &
- [Patient, exhibits_symptom, headache] &
- [Patient, exhibits_symptom, aches_and_pains]
- then
- add [Patient, exhibits_symptom, influenza] &
- announce [Patient, ' has influenza.'].
-
- rule stop forward
- if
- diagnosing /* least specific rule, so will fire last of all */
- then
- remove diagnosing &
- announce [nl,'All possible diagnoses have been found',nl,
- 'Diagnosis complete. BYE! ',nl] &
- halt.
-
- /* HOW TO RUN THIS EXAMPLE
- after loading the above rules, (using ?- kb 'flu2.kb'.)
- simply invoke the forward-chainer via
- ?- fc.
-
- The contents of working memory can be viewed at the end via
- ?- show wm.
-
- Dynamic viewing of working memory changes can be observed
- by toggling on tracing option number 5 as follows:
- ?- tracing(5).
-
- Finally, if you want to see how a conclusion was reached, use 'how',
- e.g.:
- ?- how [frank, exhibits_symptom, hay_fever].
- */
-